using System;
using System.Collections.Generic;
using System.Text;

namespace ElteIk.RoboSoccer.Core.Physics
{
	/// <summary>
	/// Common base class for physical objects.
	/// </summary>
    public class SimpleObject : IPhysicalObject
    {
		public SimpleObject()
		{
			position = new Vector2D();
			velocity = new Vector2D();
			heading = new Vector2D();
			mass = 1.0f;
			isMovable = true;
		}

		public SimpleObject(Vector2D position)
			: this()
		{
			this.position = position;
		}

        #region IPhysicalObject Members

		private Vector2D position;
		public Vector2D Position
        {
            get
            {
				return position;
            }
            set
            {
				position = value;
            }
        }

		private Vector2D velocity;
        public Vector2D Velocity
        {
            get
            {
				return velocity;
			}
            set
            {
				velocity = value;
            }
        }

		private Vector2D heading;
        public Vector2D Heading
        {
            get
            {
				return heading;
            }
            set
            {
				heading = value;
            }
        }

		private float mass;
		public float Mass
		{
			get
			{
				return mass;
			}
			set
			{
				mass = value;
			}
		}

		private bool isMovable;
		public bool IsMovable
		{
			get { return isMovable; }
			protected set { isMovable = value; }
		}

        private List<FreeVector2D> forces = new List<FreeVector2D>();
        public virtual IList<FreeVector2D> Forces
        {
            get 
            {
                return forces;
            }
        }

        private float rotation;
        public float Rotation
        {
            get { return rotation; }
            set { rotation = value; }
        }

        public virtual void Move(Vector2D movementVector)
		{
			forces.Add(movementVector);
		}

        public virtual void AddForce(FreeVector2D force)
        {
            forces.Add(force);
        }

        public virtual void ClearForces()
        {
            forces.Clear();
        }

        public IPhysicalObject Clone()
        {
            SimpleObject cloned = new SimpleObject();
            cloned.heading = new Vector2D(heading);
            cloned.isMovable = isMovable;
            cloned.mass = mass;
            cloned.position = new Vector2D(position);
            cloned.rotation = rotation;
            cloned.velocity = new Vector2D(velocity);
            foreach (FreeVector2D force in forces)
            {
                cloned.forces.Add(new FreeVector2D(force));
            }
            return cloned;
        }

		#endregion
	}
}
